<?php

namespace app\admin\controller;

use app\common\controller\Backend;

use think\Controller;
use think\Db;
use think\Request;

/**
 * 
 *
 * @icon fa fa-circle-o
 */
class Trade extends Backend
{
    
    /**
     * Trade模型对象
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('Trade');

    }

    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        //$this->request->filter(['strip_tags', 'htmlspecialchars']);
        if ($this->request->isAjax())
        {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $total = $this->model->with('user')
                ->where($where)
                ->order($sort, $order)
                ->count();

            $list = $this->model
                ->where($where)->with('user')
                ->order($sort, $order)
                ->limit($offset, $limit)
                ->select();

            foreach($list as $key=>$val){
                $year = substr($val['reldate'],0,4);
                $month = substr($val['reldate'],4,2);
                $day = substr($val['reldate'],6,2);
                $hour = substr($val['inptime'],0,2);
                $miniter = substr($val['inptime'],2,2);
                $second = substr($val['inptime'],4,2);
                $list[$key]['inpdate'] =  $year.'-'.$month.'-'.$day .' '.$hour .':'.$miniter.':'.$second;
                $tradename  = Db::name('trade_type')->where('id',$val['type'])->find();
                $list[$key]['typename'] = $tradename['name'];
                if($val['revind']==1){
                    $list[$key]['revind'] = '已撤销/冲正';
                }else{
                    $list[$key]['revind'] = '交易正常';
                }


            }


            $result = array("total" => $total, "rows" => $list);

            return json($result);
        }
        return $this->view->fetch();
    }



}
